//
//  WmcEmptyBrandView.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/6/13.
//

import UIKit
import YPBedrock

class WmcEmptyBrandView: WmcBaseBrandView {
    // Internal


    override func makeUI() {
        super.makeUI()

        addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }

    override func configBrandScale(_ scale: CGFloat) {
        let size = CGSize(width: drawImageSize.width * scale, height: drawImageSize.height * scale)
        frame = CGRect(origin: frame.origin, size: size)
    }

    override func drawImage(_ image: UIImage) {
        var size = image.size
        let wh_ratio = size.width / size.height
        if size.width > size.height { // 横版图
            size.width = maxSize.width
            size.height = size.width / wh_ratio
            if size.height > maxSize.height { // 二次缩放
                size.height = maxSize.height
                size.width = size.height * wh_ratio
            }
        } else if size.height > size.width { // 竖版图
            size.height = maxSize.height
            size.width = size.height * wh_ratio
            if size.width > maxSize.width { // 二次缩放
                size.width = maxSize.width
                size.height = size.width / wh_ratio
            }
        } else {
            size = maxSize
        }

        drawImageSize = size

        configBrand()

        super.drawImage(image)
    }

    // Private

    private var drawImageSize: CGSize = .zero
}
